package com.config;


import io.netty.util.concurrent.DefaultThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class TreadPoolConfig {


    @Bean
    public ThreadPoolExecutor getTreadPoll() {
//        corePoolSize - 保留在池中的线程数，即使它们是空闲的，除非设置allowCoreThreadTimeOut
//        maximumPoolSize –池中允许的最大线程数
//        keepAliveTime –当线程数大于核心时，这是多余的空闲线程在终止前等待新任务的最长时间
//        keepAliveTime-参数的时间单位
//        workQueue –用于在执行任务之前保存任务的队列 此队列将仅保存由execute方法提交的Runnable任务
//        threadFactory –执行器创建新线程时使用的工厂
//        handler –由于达到线程边界和队列容量而阻塞执行时使用的处理程序
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                1,
                1,
                20,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                new DefaultThreadFactory(Thread.class),
                new ThreadPoolExecutor.AbortPolicy());
        poolExecutor.execute(new Thread());
        poolExecutor.submit(new Thread());

        return poolExecutor;
    }

}


